<%@page import="java.util.ArrayList"%>
<%@page import="java.util.HashMap"%>
<%@page import="Model.Comentario"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id="user" class="Model.Usuario" scope="session"/>
<jsp:useBean id="receita" class="Model.Receita" scope="session"/>
<jsp:useBean id="comentarios" class="java.util.ArrayList" scope="session"/>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/css.css">
        <title>Detalhes da Receita</title>
    </head>
    <body>
        <section>
            <h1> Detalhe da receita ${receita.getName()}</h1>
            <table style="margin: auto;" border="1">
                <tr>
                    <td><strong>Nome</strong></td>
                    <td><strong>Ingredientes</strong></td>
                    <td><strong>Disponível</strong></td>
                    <td><strong>Tempo de preparo</strong></td>
                    <td><strong>Valor Nutricional</strong></td>
                    <td><strong>Dicas</td>
                    <td><strong>Categoria</strong></td>
                    <td><strong>Nota</strong></td>
                </tr>
                <tr>
                    <td>${receita.getName()}</td>
                    <td>${receita.getIngredientes()}</td>
                    <td>${receita.getStatus()}</td>
                    <td>${receita.getTime()}</td>
                    <td>${receita.getVal_nutri()}</td>
                    <td>${receita.getClue()}</td>
                    <td>${receita.getCategoria()}</td>
                    <td>${receita.getAvg()}</td>
                    <td><a href="ServletReceita?opt=cad&edit=${receita.getId()}">Editar</a></td>
                </tr>
            </table>
            <br>
            <br>
            <h2>Comentário</h2>
            <table border="1">
                <tr>
                    <td>Usuario</td>
                    <td>Comentario</td>
                </tr>
                <c:if test="${comentarios.size() > 0}">
                    <c:forEach var="com" items="${comentarios}">
                        <tr>
                            <td>${com.usuario_id.name}</td>
                            <td>${com.comentario}</td>
                        </tr>
                    </c:forEach>
                </c:if>

            </table>
            <br>
            <br>
            <br>
            <c:if test="${user != null}">
                <form id="insertion"  action="ServletComentarios?opt=note" method="POST">
                    <table border="1">
                        <tr> 
                            <td>
                                Atribua uma Nota : 
                            </td>
                            <td>
                                <select id="nota" name="nota">
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                </select>
                            </td>
                            <td>
                                <input type="hidden" id="nreceita" name="receita" value="${receita.getId()}">
                                <input type="hidden" id="user" name="usuario" value="${user.getId()}">
                                <input type="submit" value="Enviar">
                            </td>
                        </tr>
                    </table>
                </form>
                <br>
                <br>
                <br>
                <form id="comentario" name="comentario" action="ServletComentarios?opt=comments" method="POST">
                    <table border="1">
                        <tr>
                            <td>Comentário</td>
                            <td>
                                <textarea id="comment" name="comment"></textarea>
                                <input type="hidden" id="receita" name="receita" value="${receita.getId()}">
                                <input type="hidden" id="login" name="usuario" value="${user.getId()}">
                            </td>


                            <td><input type="submit" value="Enviar"></td>
                        <tr>
                    </table>

                </form>
            </c:if>

            <br><a href="ServletUsuario?opt=detalhes" style="margin-left: 300px;">Voltar</a>
        </section>
    </body>
</html>
